package org.example.service.impl;

import org.example.mapper.RecordMapper;
import org.example.model.Record;
import org.example.model.RecordExample;
import org.example.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecordServiceImpl implements RecordService {

    @Autowired
    private RecordMapper recordMapper;

    @Override
    public List<Record> listAll() {
        return recordMapper.selectByExample(new RecordExample());
    }

    @Override
    public int create(Record record) {
        record.setId(null);
        return recordMapper.insert(record);
    }

    @Override
    public int delete(Long id) {
        return recordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(Record record) {
        return recordMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public Record getById(Long id) {
        return recordMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Record> getByPhoneNum(int phoneNum) {
        RecordExample recordExample = new RecordExample();
        recordExample.createCriteria().andPhoneNumEqualTo(phoneNum);
        return recordMapper.selectByExample(recordExample);
    }


}
